﻿using AutoMapper;
using System;
using System.Collections.Generic;
using System.IO.MemoryMappedFiles;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;
using WeatheRx.Data;
using WeatheRx.DomainModel.Applicants;
using WeatheRx.DomainModel.Search;
using WeatheRx.Managers.Search;
using WeatheRx.Managers.Utilities;

namespace WeatheRx.Managers.Config
{
    public static class AutomapConfig
    {
        public static void InitializeMap()
        {
            Mapper.CreateMap<Applicant, ApplicantSearchResult>()
             .ForMember(opt => opt.MatchedOn, dest => dest.NullSubstitute(new List<string>()))
             .ForMember(dest => dest.JobStatus, src => src.ResolveUsing<JobStatusResolver>());
            Mapper.CreateMap<Price, PriceHeaderModel>();
        }
    }

    public class JobStatusResolver : IValueResolver
    {
        public ResolutionResult Resolve(ResolutionResult source)
        {
            var a = (Applicant)source.Context.SourceValue;
            return source.New(StatusUtilities.DetermineCurrentStatus(a), typeof(JobStatus));
        }
    }

    public class JobStatusEnumResolver : ValueResolver<JobStatus, string>
    {
        protected override string ResolveCore(JobStatus s)
        {
            switch (s)
            {
                case JobStatus.Completed:
                    return "Completed";

                case JobStatus.Deferral:
                    return "Deferral";

                case JobStatus.Walkaway:
                    return "Walkaway";

                case JobStatus.FinalInspection:
                    return "Final Inspection";

                case JobStatus.InitialInspection:
                    return "Initial Inspection";

                case JobStatus.PendingDocumentation:
                    return "Pending Documentation";

                case JobStatus.Ineligible:
                    return "Ineligible";

                case JobStatus.EligibilityApproved:
                    return "Approved";

                case JobStatus.WorkInProgress:
                    return "Work In Progress";

                default:
                    return s.ToString();
            }
        }
    }
}